<template>
	<view class="mainPage" :style="{'padding-top': `${$store.state.safeArea.top || 0}px`, 'padding-bottom': `${$store.state.safeArea.bottom || 0}px`}">
		<public-head :title="orderInfo.u_name || '聊天'"></public-head>
		<view class="content-box" @touchstart="touchstart" id="content-box" :class="{'content-showfn':showFunBtn}" @click="showFunBtn = false">
			<!-- 背景图- 定位方式 -->
			<!-- <image class="content-box-bg" :src="user_info.chatBgImg" :style="{ height: imgHeight }"></image> -->
			<view class="content-box-bg" style="background: #F5F5F6;" :style="{ height: imgHeight }"></view>
			<!-- 头部状态 -->
			<view class="fsb" style="background: #F6EAE1;width: 100%;height: 100rpx;color: #FA6400;z-index: 2;position: fixed;">
				<view class="mg-l-20" style="width: 180rpx;height: 1rpx;"></view>
				<view class="flex aic" v-if="orderInfo.status == 0">
					<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/8.png" style="width:30rpx;height:30rpx" class=""></image>
					<view class="weight mg-l-10 f24">等待接诊中</view>
				</view>
				<view class="flex aic" v-if="orderInfo.status == 2">
					<view class="weight f24">已完成</view>
				</view>
				<view class="flex aic" v-if="orderInfo.status == 3">
					<view class="weight f24">拒诊</view>
				</view>
				<view class="flex aic" v-if="orderInfo.status == 4">
					<view class="weight f24">已取消</view>
				</view>
				<view class="" v-if="orderInfo.status == 1 && orderInfo.time">
					<uni-countdown :day="orderInfo.time.day" :hour="orderInfo.time.hour" :minute="orderInfo.time.minute" :second="orderInfo.time.second" backgroundColor="" color="#FA6400" splitorColor="#FA6400" @timeup="timeup"/>
				</view>
				<view class="fcc f24 bra60 mg-r-20" style="background: linear-gradient(220deg, #F78361 0%, #F54B64 100%);width: 180rpx;height: 60rpx;" v-if="orderInfo.status == 1" @click="jieshu = true">
					<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/14.png" style="width:30rpx;height:30rpx" class=""></image>
					<view class="fff mg-l-10 f22">结束问诊</view>
				</view>
				<view class="mg-l-20" style="width: 180rpx;height: 1rpx;" v-if="orderInfo.status != 1"></view>
			</view>
			<view class="" style="height: 100rpx;width: 100%;"></view>
			<!-- <scroll-view scroll-y="true" style="height: calc(100vh - 200rpx);"> -->
			<!-- loading加载 -->
			<view class="content-box-loading" v-if="!loading">
				<u-loading mode="flower"></u-loading>
			</view>
			<view class="rel f24" style="text-align: center;color: #768196;z-index: 1;" v-show="isCompleted && messageList >= 15">没有更多数据了</view>
			<!-- 消息文本，语音，图片 -->
			<view class="message" v-for="(item, index) in messageList" :key="index" :id="`msg-${item.hasBeenSentId}`">
				<view class="f24" style="color: #909090;text-align: center;" v-if="index == 0 || item.createTime - messageList[index - 1].createTime > 60">{{item.createTimes}}</view>
				<view class="mg-t-40" style="color: #768196;text-align: center;" v-if="item.MsgType == 'CES_remind'" @click="tishi()">用户不在线？<text style="color: #419BF5;">提醒用户</text></view>
				<view class="mg-t-40" style="color: #768196;text-align: center;" v-if="item.MsgType == 'CES_phone'" @click="show = true"><text style="color: #419BF5;">点此拨打电话</text></view>
				<view class="message-item mg-t-30" :class="item.isItMe ? 'right' : 'left'" v-if="item.MsgType != 'CES_remind' && item.MsgType != 'CES_phone'">
					<image class="img" :src="item.fromUserHeadImg" mode="" @tap="linkToBusinessCard(item.fromUserId)">
					</image>
					<!-- MsgType = 1 文本 -->
					<view class="content" v-if="item.MsgType == 'TIMTextElem'"><text :user-select="true" style="line-height: 42rpx;">{{ item.content.Text }}</text></view>
					<!-- MsgType = 2 语音 -->
					<view class="content contentType2" :class="[{ 'content-type-right': item.isItMe }]"
						v-if="item.MsgType == 'TIMSoundElem'" @tap="handleAudio(item)" hover-class="contentType2-hover-class"
						:style="{width:`${130+(item.content.Second*2)}rpx`}">
						<view class="voice_icon" :class="[
									{ voice_icon_right: item.isItMe },
									{ voice_icon_left: !item.isItMe },
									{ voice_icon_right_an: item.anmitionPlay && item.isItMe },
									{ voice_icon_left_an: item.anmitionPlay && !item.isItMe }
								]"></view>
						<view class="">{{ item.content.Second }}''</view>
					</view>
					<!-- MsgType = 3 图片 -->
					<view class="content contentType3" v-if="item.MsgType == 'TIMImageElem'" @tap="viewImg([item.content.ImageInfoArray[0].URL])">
						<image :src="item.content.ImageInfoArray[2].URL" class="img" style="border-radius: 8rpx;" mode="widthFix"></image>
					</view>
					<!-- 视频 -->
					<view class="content contentType3 rel" v-if="item.MsgType == 'TIMVideoFileElem'" @tap="chakan(item.content.VideoUrl)">
						<image :src="item.content.ThumbUrl" class="img1" style="border-radius: 8rpx;" mode="widthFix" v-if="item.content.ThumbWidth > item.content.ThumbHeight"></image>
						<image :src="item.content.ThumbUrl" class="img2" style="border-radius: 8rpx;" mode="widthFix" v-else></image>
						<view class="fdc aic jsb" style="position: absolute;width: 100%;height: 100%;z-index: 2;top: 0;left: 0;">
							<view class="w100pc" style="height: 60rpx;"></view>
							<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/icon/bofang.png" style="width:50rpx;height:50rpx" class=""></image>
							<view class="f26 fff w100pc" style="text-align: right;margin-right: 20rpx;height: 60rpx;line-height: 60rpx;">{{item.content.VideoSecondText}}</view>
						</view>
					</view>
					<!-- 视频，图文，电话问诊 -->
					<view class="mg-l-20 f28" style="background: #fff;width: 500rpx;border-radius: 24rpx;" v-if="item.MsgType == 'CES_Consultation_info'" @click="tiaozhuan(1)">
						<view class="fcc" style="background: linear-gradient(220deg, #F78361 0%, #F54B64 100%);width: 180rpx;height: 60rpx;border-radius: 24rpx 0px 24rpx 0px;">
							<view class="fff f28 bold400">{{item.content.Title}}</view>
						</view>
						<view style="color: #000;" class="mg-t-20 mg-l-20 f30">病情描述：</view>
						<view class="overflow3" style="margin:20rpx;line-height: 42rpx;">
							<text style="color: #909090;line-height: 42rpx;" class="f28">{{item.content.Content}}</text>
						</view>
						<view class="fsb lrpadd-20" style="height: 80rpx;border-top: 1rpx solid rgba(0, 0, 0, 0.08);color: #959595;">
							<view class="">{{item.content.Desc}}</view>
							<view class="flex aic">
								<view class="" style="font-weight: 400;
color: #FE7600;
font-size: 26rpx;">点击查看详情</view>
								<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/24.png" style="width:15rpx;height:25rpx;margin-top: 5rpx;display: none;" class="mg-l-10"></image>
							</view>
						</view>
					</view>
					<!-- 通话小结 -->
					<!-- <view class="bra10 mg-r-20 f24" style="background: #fff;width: 75%;color: #FF912E;padding: 20rpx 0 20rpx 40rpx;" v-if="item.MsgType == 5">
						<view class="weight" style="text-align: center;">通话小结</view>
						<view class="mg-t-20">开始时间：2020-09-08 18:09:09</view>
						<view class="mg-t-20">结束时间：2020-09-08 18:19:09</view>
						<view class="mg-t-20">剩余通话时间：0分0秒</view>
					</view> -->
					<!-- 电子处方 -->
					<view class="f26" style="background: #fff;width: 500rpx;border-radius: 24rpx;margin-right: 28rpx;" v-if="item.MsgType == 'CES_Prescription'" @click="tiaozhuan(2,index)">
						<view class="flex aic" style="height: 80rpx;">
							<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/15.png" style="width:26rpx;height:30rpx" class="mg-l-20"></image>
							<view class="mg-l-20 f30" style="color: #323232;">电子处方</view>
						</view>
						<view class="fsb" style="margin: 20rpx 40rpx 0 70rpx;">
							<view class="" style="color: #323232;width: 50%;">诊断结果</view>
							<view class="" style="color: #909090;width: 50%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">{{item.content.Result}}</view>
						</view> 
						<view class="fsb" style="margin: 20rpx 40rpx 0 70rpx;" v-for="(it,i) in item.content.Drugs" :key="i" v-show="i < 2">
							<view class="" style="color: #323232;width: 50%;">药品</view>
							<view class="" style="color: #909090;width: 50%;">{{it}}</view>
						</view>
						<view class="mg-t-20" style="height: 1rpx;width: 100%;background: #F0F0F0;"></view>
						<view class="flex aic jc-end">
							<view class="fcc bra60 mg-t-20 mg-r-20" style="width: 200rpx;height: 60rpx;" :class="[item.indexs == nn ? 'bb' : 'aa']">
								<view class="fff f30">查看处方</view>
							</view>
						</view>
						<view class="h2 w100pc"></view>
					</view>
					<!-- 医嘱 -->
					<view class="f26" style="background: #fff;width: 500rpx;border-radius: 24rpx;margin-right: 28rpx;" v-if="item.MsgType == 'CES_MedicalAdvice'" @click="tiaozhuan(3)">
						<view class="flex aic" style="height: 80rpx;">
							<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/15.png" style="width:26rpx;height:30rpx" class="mg-l-20"></image>
							<view class="mg-l-20 f30" style="color: #323232;">医生医嘱</view>
						</view>
						<view class="fsb" style="margin: 20rpx 40rpx 0 70rpx;">
							<view class="" style="color: #323232;width: 50%;">诊断结果</view>
							<view class="" style="color: #909090;width: 50%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">{{item.content.Result}}</view>
						</view>
						<view class="fsb" style="margin: 20rpx 40rpx 0 70rpx;">
							<view class="" style="color: #323232;width: 50%;">诊断建议</view>
							<view class="" style="color: #909090;width: 50%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">{{item.content.Proposal}}</view>
						</view>
						<view class="mg-t-20" style="height: 1rpx;width: 100%;background: #F0F0F0;"></view>
						<view class="flex aic jc-end">
							<view class="fcc bra60 mg-t-20 mg-r-20" style="width: 200rpx;height: 60rpx;background: linear-gradient(270deg, #F78361 0%, #F54B64 100%);">
								<view class="fff f30">查看医嘱</view>
							</view>
						</view>
						<view class="h2 w100pc"></view>
					</view>
					<!-- 评价 -->
					<view class="f26" style="background: #fff;width: 500rpx;margin-right: 28rpx;border-radius: 24rpx;" v-if="item.MsgType == 'CES_evaluate'">
						<view class="flex aic" style="height: 80rpx;">
							<image src="../../static/pj.png" style="width:35rpx;height:35rpx" class="mg-l-20"></image>
							<view class="mg-l-20 f30" style="color: #323232;">评价</view>
						</view>
						<view class="mg-t-20" style="height: 1rpx;width: 100%;background: #F0F0F0;"></view>
						<view class="fcc" style="margin: 20rpx 40rpx 0 40rpx;">
							<view class="f28" style="color: #323232;">请对本次服务做出评价！</view>
						</view>
						<!-- <view class="fcc">
							<view class="fcc bra10 mg-t-40" style="width: 200rpx;height: 70rpx;background: #FE7600;">
								<view class="fff">点击评价</view>
							</view>
						</view> -->
						<view class="h2 w100pc"></view>
					</view>
				</view>
			</view>
			<!-- </scroll-view> -->
		</view>
		<view class="h2 w100pc" id="dddd"></view>
		<view class="" style="width: 100%;height: 420rpx;" v-show="showFunBtn"></view>
		<!-- 底部聊天输入框 -->
		<view class="input-box" :class="{ 'input-box-mpInputMargin': mpInputMargin}" v-if="orderInfo.status == 1">
			<view class="input-box-flex">
				<!-- H5 -->
				<image v-if="chatType === 'voice'" class="icon_img" :src="require('@/static/voice.png')"
					@click="switchChatType('keyboard')"></image>
				<image v-if="chatType === 'keyboard'" class="icon_img" :src="require('@/static/keyboard.png')"
					@click="switchChatType('voice')"></image>
				<view class="input-box-flex-grow">
					<input v-if="chatType === 'voice'" type="text" class="content" id="input" v-model="formData.content"
						:hold-keyboard="true" :confirm-type="'send'" :confirm-hold="true" @focus="shuru"
						placeholder-style="color:#A39A9A;font-size: 32rpx;" :cursor-spacing="10" @confirm="$noMultipleClicks(send_Msg)"
						style="color: #000;background: #F3F4F6 !important;border-radius: 60rpx;font-size: 32rpx;" />
					<view class="voice_title" v-if="chatType === 'keyboard'"
						:style="{ background: recording ? '#c7c6c6' : '#FFFFFF' }" @touchstart.stop.prevent="startVoice"
						@touchmove.stop.prevent="moveVoice" @touchend.stop="endVoice" @touchcancel.stop="cancelVoice">
						{{ voiceTitle }}
					</view>
				</view>

				<!-- 功能性按钮 -->
				<image class=" icon_btn_add" :src="require('@/static/add.png')" @tap="switchFun"></image>
				<!-- <image class=" icon_btn_add" :src="require('@/static/adds.png')" @tap="switchFun" v-show="showFunBtn"></image> -->

				<!-- #ifdef H5 -->
				<!-- <button class="btn" type="primary" size="mini" @touchend.prevent="sendMsg(null)">发送</button> -->
				<!-- #endif -->
			</view>

			<view class="fun-box" :class="{'show-fun-box':showFunBtn}">
				<u-grid :col="4" hover-class="contentType2-hover-class" :border="false" @click="clickGrid">
					<u-grid-item v-for="(item, index) in funList" :index="index" :key="index" bg-color="#F6F6F6" v-show="item.flag">
						<image :src="item.img" style="width:100rpx;height:100rpx;border-radius: 25rpx;" class="">
						</image>
						<view class="grid-text">{{ item.title }}</view>
					</u-grid-item>
				</u-grid>
			</view>

		</view>
		
		<!-- 待接诊 -->
		<view class="" style="position: fixed;z-index: 2;bottom: 150rpx;left: 0;width: 100%;" v-if="orderInfo.status == 0">
			<view class="w100pc fsa">
				<view class="fcc bra10" style="width: 240rpx;height: 80rpx;border: 1rpx solid #FF9331;background: #F5F5F6;" @click="shows = true">
					<view class="" style="color: #F67761;">退诊</view>
				</view>
				<view class="fcc bra10" style="width: 240rpx;height: 80rpx;background: #FF9331;" @click="jiezhen">
					<view class="" style="color: #fff;">接诊</view>
				</view>
			</view>
		</view>
		
		
		<!-- //语音动画 -->
		<view class="voice_an" v-if="recording" style="z-index: 2;">
			<view class="voice_an_icon">
				<view id="one" class="wave"></view>
				<view id="two" class="wave"></view>
				<view id="three" class="wave"></view>
				<view id="four" class="wave"></view>
				<view id="five" class="wave"></view>
				<view id="six" class="wave"></view>
				<view id="seven" class="wave"></view>
			</view>
			<view class="text">{{voiceIconText}} ({{voiceTime}}s)</view>
		</view>

		<!-- 常用语 -->
		<u-popup v-model="changyongyu" mode="center" length="90%" border-radius="15">
			<view style="background: #fff;">
				<view class="h2 w100pc"></view>
				<scroll-view scroll-y="true" style="max-height: 60vh;font-weight: bold;" v-if="cy_lieb.system">
					<view class="mg-l-20">系统常用语 ({{cy_lieb.system.length}})</view>
					<view class="mg-l-40 mg-t-20 mg-r-20 fsb" style="" v-for="(it,i) in cy_lieb.system" :key="i" @click="dianji(it,1,i)">
						<view class="" style="width: 85%;">{{it.content}}</view>
						<image src="../../static/t.png" style="width:40rpx;height:40rpx" class="" v-show="it.flag == 0"></image>
						<image src="../../static/ts.png" style="width:40rpx;height:40rpx" class="" v-show="it.flag == 1"></image>
					</view>
					<view class="mg-t-20 mg-l-20">自定义常用语 ({{cy_lieb.custom.length}})</view>
					<view class="mg-l-40 mg-t-20 mg-r-20 fsb" style="" v-for="(it,i) in cy_lieb.custom" :key="i" @click="dianji(it,2,i)">
						<view class="" style="width: 85%;">{{it.content}}</view>
						<image src="../../static/t.png" style="width:40rpx;height:40rpx" class="" v-show="it.flag == undefined || it.flag == 0"></image>
						<image src="../../static/ts.png" style="width:40rpx;height:40rpx" class="" v-show="it.flag == 1"></image>
					</view> 
				</scroll-view>
				<view class="fcc mg-t-40">
					<button type="default" class="bra60" style="background: #FE7600;color: #fff;width: 80%;font-size: 26rpx;" @click="fasong">发送</button>
				</view>
				<view class="h2 w100pc"></view>
			</view>
		</u-popup>
		<!-- 结束订单 -->
		<u-popup v-model="jieshu" mode="center" length="90%" border-radius="15" :mask-close-able="false">
			<view style="background: #fff;">
				<view class="fcc" style="width: 100%;height: 100rpx;">
					<view class="weight">结束问诊</view>
				</view>
				<view class="flex aic" style="height: 101rpx;border-top: 1px solid #EEEEEE;">
					<view class="fcc" style="width: calc(50% - 0.5rpx);height: 100rpx;" @click="jieshu = false">
						<view class="">取消</view>
					</view>
					<view class="" style="width: 1rpx;height: 100rpx;background: #eee;"></view>
					<view class="fcc" style="width: calc(50% - 0.5rpx);height: 100rpx;" @click="queding">
						<view class="" style="color: #FA6400;">确定</view>
					</view>
				</view>
			</view>
		</u-popup>
		<!-- 拨打电话 -->
		<u-popup v-model="show" mode="center" length="90%" border-radius="15" :mask-close-able="false">
			<view style="background: #fff;">
				<view class="fcc" style="width: 100%;height: 100rpx;">
					<view class="weight">拨打提示：请您尽快与患者进行通话</view>
				</view>
				<view class="mg-b-40 fdc aic" style="text-align: center;">
					<view class="">即将用该号码呼出</view>
					<input type="number" placeholder="请输入本机号" v-model="orderInfo.doc_phone" class="mg-t-20 weight f40" />
					<view class="f22 mg-t-20" style="color: #FA6400;">( 如不是本机号，请修改 ↑ )</view>
					<view class="mg-t-10 f22">宠e生为您提供号码保护,对方看不见您的真实手机号</view>
				</view>
				<view class="flex aic" style="height: 101rpx;border-top: 1px solid #EEEEEE;">
					<view class="fcc" style="width: calc(50% - 0.5rpx);height: 100rpx;" @click="show = false">
						<view class="">取消</view>
					</view>
					<view class="" style="width: 1rpx;height: 100rpx;background: #eee;"></view>
					<view class="fcc" style="width: calc(50% - 0.5rpx);height: 100rpx;" @click="hujiao()">
						<view class="" style="color: #FA6400;">呼叫(加密)</view>
					</view>
				</view>
			</view>
		</u-popup>
		<!-- 退诊原因 -->
		<u-popup v-model="shows" mode="center" length="90%" border-radius="15" :mask-close-able="false">
			<view style="background: #fff;">
				<view class="fcc" style="width: 100%;height: 100rpx;">
					<view class="weight">退诊原因</view>
				</view>
				<view class="fcc" style="">
					<textarea maxlength="200" v-model="tz_yy" class="bra10 lrmg-40 f26" style="border: 1rpx solid #DDDDDD;" />
				</view>
				<view style="margin: 10rpx 70rpx 40rpx 40rpx;text-align: right;color: #999999;">{{tz_yy.length}}/200</view>
				<view class="flex aic" style="height: 101rpx;border-top: 1px solid #EEEEEE;">
					<view class="fcc" style="width: calc(50% - 0.5rpx);height: 100rpx;" @click="shows = false">
						<view class="">取消</view>
					</view>
					<view class="" style="width: 1rpx;height: 100rpx;background: #eee;"></view>
					<view class="fcc" style="width: calc(50% - 0.5rpx);height: 100rpx;" @click="tuizhen()">
						<view class="" style="color: #FA6400;">确认</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script> 
	var that
	import publicHead from "@/components/publicHead/publicHead.vue"
	import uniCountdown from '@/pagesB/components/uni-countdown/uni-countdown.vue'
	export default {
		components: {
			publicHead,
			uniCountdown
		},
		data() {
			return {
				show:false,
				shows:false,
				jieshu:false,
				changyongyu:false,
				tz_yy:'',//退诊原因
				fromUserInfo: {},
				formData: {
					content: '',
					limit: 15,
					index: 1
				},
				messageList: [],
				loading: true, //标识是否正在获取数据
				imgHeight: '1000px',
				mpInputMargin: false, //适配微信小程序 底部输入框高度被顶起的问题
				chatType: "voice", // 图标类型 'voice'语音 'keyboard'键盘
				voiceTitle: '按住 说话',
				Recorder: uni.getRecorderManager(),
				Audio: '',
				recording: false, //标识是否正在录音
				isStopVoice: false, //加锁 防止点击过快引起的当录音正在准备(还没有开始录音)的时候,却调用了stop方法但并不能阻止录音的问题
				voiceInterval: null,
				voiceTime: 0, //总共录音时长
				canSend: true, //是否可以发送
				PointY: 0, //坐标位置
				voiceIconText: "正在录音",
				showFunBtn: false, //是否展示功能型按钮
				AudioExam: null, //正在播放音频的实例
				funList: [{
						img: 'https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/1.png',
						title: "快捷回复",
						flag:true
					},
					{
						img: 'https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/2.png',
						title: "开具处方",
						flag:true
					},
					{
						img: 'https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/3.png',
						title: "电话问诊",
						flag:false
					},
					// {
					// 	img: 'https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/4.png',
					// 	title: "视频问诊"
					// },
					{
						img: 'https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/5.png',
						title: "发送图片",
						flag:true
					},
					{
						img: 'https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/6.png',
						title: "发送视频",
						flag:true
					},
					{
						img: 'https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/lt/7.png',
						title: "医嘱",
						flag:true
					}
				],
				user_info: {
					headImg: 'https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/image/guanxi.jpg', //头像
					id: 1, //id
					userName: 'DR', //昵称
					wechatNumber: 'October', //微信号
					signature: 'who do you want to meet.', //个性签名
					phone: '13535351112', //手机号
					pictureBanner: 'https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/image/circleBanner/3.jpg', //相册背景图
					chatBgImg: 'https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/image/Ran.jpg', //聊天背景图
					address: "河南郑州"
				},
				orderInfo:{},
				nextReqMessageID:'',
				isCompleted:false,
				cy_lieb:[],//常用语列表
				item_info:{content:''},
				is_yuyin:0,//0未播放，1正在播放
				Audios:{hasBeenSentId:0},
				IS:0,//开启上拉0，正在上拉1
				noClick:true,
				nn:-1,
				luyin_type:0,//0未开启麦克风，1已开启麦克风
			};
		},
		methods: {
			// 复制
			
			copy(value){
			  //提示模板
			  uni.showModal({
				content:value,//模板中提示的内容
				confirmText:'复制内容',
				success:()=>{//点击复制内容的后调函数
				  //uni.setClipboardData方法就是讲内容复制到粘贴板
				  uni.setClipboardData({
					data:value,//要被复制的内容
					success:()=>{//复制成功的回调函数
					  uni.showToast({//提示
						title:'复制成功'
					  })
					}
				  });
				}
			  });
			},
			// 提示用户上线
			tishi(){
				uni.showLoading({
					mask: true,
					title: '正在发送...'
				});
				let postData = {
					order_sn:that.orderInfo.order_id
				}
				that.$postAjax1('Doc_order_send_sms',postData,function(data){
					uni.showToast({
						title: '发送成功',
						icon: 'success',
						duration: 1500
					});
				})
			},
			hujiao(){
				if(that.orderInfo.doc_phone == ''){
				uni.showToast({
					title: '请输入手机号码',
					icon: 'none',
					duration: 1500
				});
				return
				}
				uni.showLoading({
					mask: true,
					title: '加载中...'
				});
				let postData = {
					// bindNumberA:that.orderInfo.doc_phone,
					// bindNumberB:that.orderInfo.phone
					order_id:that.orderInfo.order_id,
					mobile:that.orderInfo.doc_phone
				}
				that.$postAjax1('Ask_consultation',postData,function(data){
					uni.hideLoading()
					// console.log(data.data);
					uni.makePhoneCall({ 
					    phoneNumber: data.data.data.secretNo
					});
					that.show = false
				})
			},
			// 跳转详情
			tiaozhuan(e,n){
				if(e == 1){
					// 查看宠物详情
					uni.navigateTo({
						url:'../../pagesA/workbench/clinicalReception/articleDetails?id=' + that.orderInfo.order_id
					})	
				}else if(e == 2){
					// 查看处方
					let arr = []
					for (var i = 0; i < that.messageList.length; i++) {
						if(that.messageList[i].MsgType == 'CES_Prescription'){
							arr.push(i)
						}
					}
					if(arr[arr.length - 1] == n){
						uni.navigateTo({
							url:'../../pagesA/workbench/clinicalReception/prescriptionDetail?id=' + that.orderInfo.order_id
						})
					}else{
						uni.showToast({
							title: '已失效',
							icon: 'none',
							duration: 1500
						});
					}
					console.log('arr',arr);
					
				}else if(e == 3){
					// 查看医嘱
					uni.navigateTo({
						url:'../../pagesA/workbench/clinicalReception/doctorAdviceDetail?id=' + that.orderInfo.order_id
					})
				}
			},
			// 结束问诊
			queding(){
				let id = JSON.stringify(that.orderInfo.order_id)//深拷贝
				let ids = JSON.parse(id)//拷贝成功
				uni.showLoading({
					mask: true,
					title: '加载中...'
				});
				let postData = {
					orderId:that.orderInfo.order_id
				}
				that.$postAjax1('Doctor_closeOrder',postData,function(data){
					uni.hideLoading()
					let postDatas = {
						orderId:that.orderInfo.order_id,
						status:that.orderInfo.consultation_type
					}
					that.$postAjax1('Doctor_getOrderInfo',postDatas,function(data){
						that.orderInfo = data.data.data
						that.orderInfo.order_id = ids
						that.jieshu = false
						console.log(that.orderInfo,'用户详情');
					})
				})
			},
			//退诊
			tuizhen(){
				if(that.tz_yy == ''){
				uni.showToast({
					title: '请输入退诊原因',
					icon: 'none',
					duration: 1500
				});
				return
				}
				uni.showLoading({
					mask: true,
					title: '加载中...'
				});
				let postData = {
					status:3,
					orderId:that.orderInfo.order_id,
					reason:that.tz_yy
				}
				that.$postAjax1('Doctor_acceptDiagnosis',postData,function(data){
					uni.hideLoading()
					that.shows = false
					that.orderInfo.status = 3
				})
			},
			//接诊
			jiezhen(){
				let id = JSON.stringify(that.orderInfo.order_id)//深拷贝
				let ids = JSON.parse(id)//拷贝成功
				uni.showLoading({
					mask: true,
					title: '加载中...'
				});
				let postData = {
					status:1,
					orderId:that.orderInfo.order_id
				}
				that.$postAjax1('Doctor_acceptDiagnosis',postData,function(data){
					uni.hideLoading()
					let postDatas = {
						orderId:that.orderInfo.order_id,
						status:that.orderInfo.consultation_type
					}
					that.$postAjax1('Doctor_getOrderInfo',postDatas,function(data){
						that.orderInfo = data.data.data
						that.orderInfo.order_id = ids
						console.log(that.orderInfo,'用户详情');
					})
				})
			},
			//拼接消息 处理滚动
			async joinData(item,flag) {
				console.log('拼接消息')
				// console.log(that.user_info);
				if (!that.loading) {
					//如果没有获取数据 即loading为false时，return 避免用户重复上拉触发加载
					return;
				}
				that.loading = false;
				const data = await that.getMessageData(item);
				console.log(data,'66666data');
				//获取节点信息
				// const {
				// 	index
				// } = that.formData;
				// const sel = `#msg-${this.messageList.length > 1 ? this.messageList[0].hasBeenSentId : data[data.length - 1].hasBeenSentId}`;
					// console.log(that.messageList[0].hasBeenSentId);
					// console.log(data[data.length - 1].hasBeenSentId,55555555)
				that.messageList = [...data, ...that.messageList];
				that.isCompleted = flag
				//填充数据后，视图会自动滚动到最上面一层然后瞬间再跳回bindScroll的指定位置 ---体验不是很好，后期优化
				that.$nextTick(() => {
					if (this.messageList.length > 1 || data.length > 1) {
						const sel = `#msg-${this.messageList.length > 1 ? this.messageList[0].hasBeenSentId : data[data.length - 1].hasBeenSentId}`;
						that.bindScroll(sel);
					}
					//如果还有数据
					if (that.formData.limit >= data.length) {
						that.formData.index++;
						setTimeout(() => {
							that.loading = true;
						}, 200);
					}
				});
			},
			//处理滚动
			bindScroll(sel, duration = 0) {
				const query = uni.createSelectorQuery().in(that);
				query
					.select(sel)
					.boundingClientRect(data => {
						uni.pageScrollTo({
							scrollTop: data && data.top - 40,
							duration
						});
					})
					.exec();
			},
			//获取消息
			getMessageData(item) {
				console.log('获取消息')
				let getData = () => {
					let arr = [];
					for (let i = 0; i < item.length; i++) {
						// const isItMe = Math.random() > 0.5 ? true : false;
						// console.log(TTinfo.MsgContent.relation);
						// console.log(JSON.parse(item[i].payload.data));
						if(!item[i].payload.data){
							continue
						}
						console.log('我是item[i].payload.data',item[i].payload.data)
						console.log('嘻嘻嘻TTinfosss',TTinfo)
						let TTinfo = JSON.parse(item[i].payload.data)
						// console.log(TTinfo.MsgContent.relation);
						if(that.orderInfo.order_id == TTinfo.MsgContent.relation){
							if(TTinfo.MsgType == 'CES_Prescription'){
								arr.push({
									hasBeenSentId: item[i].ID, //已发送过去消息的id
									content: TTinfo.MsgContent,
									fromUserHeadImg: item[i].avatar, //用户头像
									fromUserId: item[i].from,
									isItMe:item[i].from == that.$store.state.im_id ? true : false, //true此条信息是我发送的 false别人发送的
									createTime: item[i].time,
									createTimes: Date.parse(new Date())/1000 - item[i].time > 86400 ? that.formatDate(item[i].time,'yyyy-MM-dd hh:mm:sss') : that.formatDate(item[i].time,'hh:mm'),
									MsgType:TTinfo.MsgType, // 1文字文本 2语音  3图片 4图文电话视频问诊 5通话小结 6电子处方 7视频未接听
									// 发送类型 1=TIMTextElem=文本消息元素,2=TIMLocationElem=地理位置消息元素,3=TIMFaceElem=表情消息元素,4=TIMCustomElem=自定义消息元素,5=TIMSoundElem=语音消息元素,6=TIMImageElem=图像消息元素, 7=TIMFileElem=文件消息元素,8=TIMVideoFileElem=视频消息元素,9=CES_SYS_Text=宠e生 问诊 系统消息,10=CES_Call_Summary=宠e生 问诊 通话小结,11=CES_Prescription=宠e生 问诊 电子处方, 12=CES_MedicalAdvice=宠e生 问诊 医嘱,13=CES_evaluate=宠e生 问诊 评价
									anmitionPlay: false,
									indexs:i
								});
								that.nn = i
								console.log('that.nn',that.nn);
							}else{
								arr.push({
									hasBeenSentId: item[i].ID, //已发送过去消息的id
									content: TTinfo.MsgContent,
									fromUserHeadImg: item[i].avatar, //用户头像
									fromUserId: item[i].from,
									isItMe:item[i].from == that.$store.state.im_id ? true : false, //true此条信息是我发送的 false别人发送的
									createTime: item[i].time,
									createTimes: Date.parse(new Date())/1000 - item[i].time > 86400 ? that.formatDate(item[i].time,'yyyy-MM-dd hh:mm:sss') : that.formatDate(item[i].time,'hh:mm'),
									MsgType:TTinfo.MsgType, // 1文字文本 2语音  3图片 4图文电话视频问诊 5通话小结 6电子处方 7视频未接听
									// 发送类型 1=TIMTextElem=文本消息元素,2=TIMLocationElem=地理位置消息元素,3=TIMFaceElem=表情消息元素,4=TIMCustomElem=自定义消息元素,5=TIMSoundElem=语音消息元素,6=TIMImageElem=图像消息元素, 7=TIMFileElem=文件消息元素,8=TIMVideoFileElem=视频消息元素,9=CES_SYS_Text=宠e生 问诊 系统消息,10=CES_Call_Summary=宠e生 问诊 通话小结,11=CES_Prescription=宠e生 问诊 电子处方, 12=CES_MedicalAdvice=宠e生 问诊 医嘱,13=CES_evaluate=宠e生 问诊 评价
									anmitionPlay: false
								});
							}
						}
					}
					return arr;
				};
				return new Promise((resolve, reject) => {
					const data = getData();
					setTimeout(() => {
						resolve(data);
					}, 500);
				});
			},
			//切换语音或者键盘方式
			switchChatType(type) {
				that.chatType = type;
				that.showFunBtn = false;
			},
			// 输入框聚焦时触发
			shuru(e){
				if(that.showFunBtn){
					that.showFunBtn = !that.showFunBtn;
				}
			},
			//切换功能性按钮
			switchFun() {
				that.showFunBtn = !that.showFunBtn;
				that.chatType = 'keyboard'
				if(that.showFunBtn){
					setTimeout(function(){
						uni.pageScrollTo({
							scrollTop: 99999,
							// selector:'#dddd',
							duration: 0, //小程序如果有滚动效果 input的焦点也会随着页面滚动...
							complete(res){
								console.log('res',res);
							}
						});
					},10)
				}
				console.log('that.showFunBtn',that.showFunBtn);
				uni.hideKeyboard()
			},
			// 发送文本消息
			send_Msg(){
				if(that.formData.content == ''){
					uni.showToast({
						title: '请输入内容',
						icon: 'none',
						duration: 1500
					});
					return
				}
				uni.showLoading({
					mask: true,
					title: '加载中...'
				});
				let postData = {
					to_uid:that.orderInfo.uid,
					type:1,
					relation:that.orderInfo.order_id,
					content:JSON.stringify({Text:that.formData.content})
				}
				that.$postAjax1('Doc_SendChat_doc_send_user',postData,function(data){
					uni.hideLoading()
					that.formData.content = '';
				})
			},
			//接收所有消息进行转换赋值
			sendMsg(data) {
				console.log('消息赋值',data);
				data = data[0]
				let TTinfo = JSON.parse(data.payload.data)
				// console.log();
				if(TTinfo.MsgContent.relation != that.orderInfo.order_id){
					return
				}
				let params
				if(TTinfo.MsgType == 'CES_Prescription'){
					params = {
						hasBeenSentId: data.ID, //已发送过去消息的id
						content: TTinfo.MsgContent,
						fromUserHeadImg: data.avatar, //用户头像
						fromUserId: data.from,
						isItMe: data.from == that.$store.state.im_id ? true : false, //true此条信息是我发送的  false别人发送的
						createTime: data.time,
						createTimes: that.formatDate(data.time,'hh:mm'),
						MsgType: TTinfo.MsgType,
						anmitionPlay:false,
						indexs:that.messageList.length
					};
					that.nn = that.messageList.length
				}else{
					params = {
						hasBeenSentId: data.ID, //已发送过去消息的id
						content: TTinfo.MsgContent,
						fromUserHeadImg: data.avatar, //用户头像
						fromUserId: data.from,
						isItMe: data.from == that.$store.state.im_id ? true : false, //true此条信息是我发送的  false别人发送的
						createTime: data.time,
						createTimes: that.formatDate(data.time,'hh:mm'),
						MsgType: TTinfo.MsgType,
						anmitionPlay:false
					};
				}

				// if (TTinfo) {
				// 	if (TTinfo.MsgType == 'TIMSoundElem') {
				// 		//说明是发送语音
				// 		// params.contentDuration = TTinfo.MsgContent.Second;
				// 		params.anmitionPlay = false;
				// 	}
				// }

				that.messageList.push(params);

				that.$nextTick(() => {
					// #ifdef MP-WEIXIN
					if (params.MsgType == 'TIMTextElem') {
						uni.pageScrollTo({
							scrollTop: 99999,
							duration: 0, //小程序如果有滚动效果 input的焦点也会随着页面滚动...
						});
					} else {
						setTimeout(() => {
							uni.pageScrollTo({
								scrollTop: 99999,
								duration: 0, //小程序如果有滚动效果 input的焦点也会随着页面滚动...
							});
						}, 150)
					}
					// #endif

					// #ifndef MP-WEIXIN
					uni.pageScrollTo({
						scrollTop: 99999,
						duration: 100
					});
					// #endif

					if (that.showFunBtn) {
						that.showFunBtn = false;
					}

					// #ifdef MP-WEIXIN 
					if (params.MsgType == 'TIMTextElem') {
						that.mpInputMargin = true;
					}
					// #endif
					//h5浏览器并没有很好的办法控制键盘一直处于唤起状态 而且会有样式性的问题
					// #ifdef H5
					uni.hideKeyboard();
					// #endif
				});
			},
			//用户触摸屏幕的时候隐藏键盘
			touchstart() {
				uni.hideKeyboard();
			},
			//准备开始录音
			startVoice(e) {
				if(that.luyin_type == 0){
				console.log('that.luyin_type',that.luyin_type)
					that.huanqi()
					return
				}
				if (that.is_yuyin == 1) {
					//如果音频正在播放 先暂停。
					console.log('that.is_yuyin',that.is_yuyin)
					that.stopAudio(that.AudioExam)
				}
				console.log('that.luyin_type',that.luyin_type)
				that.recording = true;
				that.isStopVoice = false;
				that.canSend = true;
				that.voiceIconText = "正在录音"
				that.PointY = e.touches[0].clientY;
				that.Recorder.start({
					format: 'mp3'
				});
			},
			//录音已经开始
			beginVoice() {
				if (that.isStopVoice) {
					that.Recorder.stop();
					return;
				}
				that.voiceTitle = '松开 结束'
				that.voiceInterval = setInterval(() => {
					if(that.voiceTime == 59){
						that.Recorder.stop();
					}
					that.voiceTime++;
				}, 1000)
			},
			//move 正在录音中
			moveVoice(e) {
				const PointY = e.touches[0].clientY
				const slideY = that.PointY - PointY;
				if (slideY > uni.upx2px(120)) {
					that.canSend = false;
					that.voiceIconText = '松开手指 取消发送 '
				} else if (slideY > uni.upx2px(60)) {
					that.canSend = true;
					that.voiceIconText = '手指上滑 取消发送 '
				} else {
					that.voiceIconText = '正在录音'
				}
			},
			chakan(e){
				uni.navigateTo({
					url:'../../pagesA/browseVideo/browseVideo?src=' + e
				})
			},
			//结束录音
			endVoice() {
				that.isStopVoice = true; //加锁 确保已经结束录音并不会录制
				that.Recorder.stop();
				that.voiceTitle = '按住 说话'
			},
			//录音被打断
			cancelVoice(e) {
				that.voiceTime = 0;
				that.voiceTitle = '按住 说话';
				that.canSend = false;
				that.Recorder.stop();
			},
			//处理录音文件
			handleRecorder({
				tempFilePath,
				duration
			}) {
				let contentDuration;
				// #ifdef MP-WEIXIN
				that.voiceTime = 0;
				if (duration < 600) {
					that.voiceIconText = "说话时间过短";
					setTimeout(() => {
						that.recording = false;
					}, 200)
					return;
				}
				contentDuration = duration / 1000;
				// console.log(contentDuration);
				// #endif

				// #ifdef APP-PLUS
				// contentDuration = that.voiceTime + 1;
				// that.voiceTime = 0;
				// if (contentDuration <= 0) {
				// 	that.voiceIconText = "说话时间过短";
				// 	setTimeout(() => {
				// 		that.recording = false;
				// 	}, 200)
				// 	return;
				// };
				// #endif

				that.recording = false;
				console.log('duration',duration);
				if(that.canSend){
					that.$util.Upload(tempFilePath,function(data){
						console.log('JSON.parse(data.data)',JSON.parse(data.data));
						data = JSON.parse(data.data)
						if(data.code == 1){
							let postData = {
								to_uid:that.orderInfo.uid,
								type:5,
								relation:that.orderInfo.order_id,
								content:JSON.stringify({Url:data.data.URL,Size:data.data.Size,Second:Math.round(duration/1000)})
							}
							that.$postAjax1('Doc_SendChat_doc_send_user',postData,function(data){
							})
						}else{
							uni.showToast({
								title: data.msg,
								icon: 'none',
								duration: 2500
							});
						}
					})
				}
				return
				// const params = {
				// 	MsgType: 'TIMSoundElem',
				// 	content: tempFilePath,
				// 	contentDuration: Math.ceil(contentDuration)
				// };
				// that.canSend && that.sendMsg(params);
			},
			//控制播放还是暂停音频文件
			handleAudio(item) {
				console.log('item',item);
				that.AudioExam = item;
				if(that.is_yuyin == 0){
					that.playAudio(item)
				}else{
					if(item.hasBeenSentId != that.Audios.hasBeenSentId){
						that.playAudio(item)
					}else{
						that.stopAudio(item)
					}
				}
			},
			//播放音频
			playAudio(item) {
				if(that.is_yuyin == 0){
					that.Audio.src = item.content.Url;
					that.Audio.hasBeenSentId = item.hasBeenSentId;
					that.Audios = item
					that.Audio.play();
					item.anmitionPlay = true;	
				}else{
					that.stopAudio(that.Audios)
					setTimeout(function(){
						that.Audio.src = item.content.Url;
						that.Audio.hasBeenSentId = item.hasBeenSentId;
						that.Audios = item
						that.Audio.play();
						item.anmitionPlay = true;	
					},200)
				}
			},
			//停止音频
			stopAudio(item) {
				console.log(item,'quxiao');
				item.anmitionPlay = false;
				// that.Audio.src = '';
				that.Audio.stop();
			},
			//关闭动画
			closeAnmition() {
				console.log('关闭动画');
				const hasBeenSentId = that.Audio.hasBeenSentId;
				const item = that.messageList.find(it => it.hasBeenSentId == hasBeenSentId);
				item.anmitionPlay = false;
			},
			fasong(){
				console.log('that.item_info',that.item_info);
				if(that.item_info.content == ''){
					uni.showToast({
						title: '请选择',
						icon: 'none',
						duration: 1500
					});
					return
				}
				uni.showLoading({
					mask: true,
					title: '加载中...'
				});
				let postData = {
					to_uid:that.orderInfo.uid,
					type:1,
					relation:that.orderInfo.order_id,
					content:JSON.stringify({Text:that.item_info.content})
				}
				that.$postAjax1('Doc_SendChat_doc_send_user',postData,function(data){
					that.changyongyu = false
					uni.hideLoading()
				})
			},
			chufa(){
				if(that.cy_lieb == ''){
					that.$postAjax1('Doctorsside_service_settings','',function(data){
						let cy_lieb = data.data.data.commonwords
						cy_lieb.system.map(item =>{
							item.flag = 0
						})
						if(cy_lieb.custom.length > 0){
							cy_lieb.custom.map(item =>{
								item.flag = 0
							})
						}
						that.cy_lieb = cy_lieb
						console.log(that.cy_lieb,'常用语列表');
						that.changyongyu = true
					})
				}else{
					that.changyongyu = true
				}
			},
			dianji(it,e,n){
				//系统常用语system 1  自定义常用语custom 2
				let cy_lieb = that.cy_lieb
				if(e == 1){
					for(let i = 0;i < cy_lieb.system.length;i++){
						if(i == n){
							cy_lieb.system[i].flag = 1
						}else{
							cy_lieb.system[i].flag = 0
						}
					}
					for (let i = 0; i < cy_lieb.custom.length; i++) {
						cy_lieb.custom[i].flag = 0
					}
				}else{
					for(let i = 0;i < cy_lieb.custom.length;i++){
						if(i == n){
							cy_lieb.custom[i].flag = 1
						}else{
							cy_lieb.custom[i].flag = 0
						}
					}
					for (let i = 0; i < cy_lieb.system.length; i++) {
						cy_lieb.system[i].flag = 0
					}
				}
				that.item_info = it
			},
			chufas(){
				that.$postAjax1('Doctorsside_service_settings','',function(data){
					let cy_lieb = data.data.data.commonwords
					cy_lieb.system.map(item =>{
						item.flag = 0
					})
					if(cy_lieb.custom.length > 0){
						cy_lieb.custom.map(item =>{
							item.flag = 0
						})
					}
					that.cy_lieb = cy_lieb
					console.log(that.cy_lieb,'常用语列表');
				})
			},
			//点击宫格时触发
			clickGrid(index) {
				if (index == 0) {
					that.chufa()
				} else if (index == 1) {
					uni.showLoading({
						mask: true,
						title: '正在跳转...'
					});
					that.$postAjax1('Doctorsside_get_prescription',{order_sn:that.orderInfo.order_id},function(data){
						uni.hideLoading()
						uni.navigateTo({
							url:'../../pagesA/workbench/clinicalReception/prescribe?item=' + JSON.stringify(that.orderInfo)
						})
					})
				} else if (index == 2) {
					that.show = true
				} else if (index == 3) {
					that.chooseImage(['album','camera'])
				} else if (index == 4) {
					that.choosevideo()
				} else if (index == 5) {
					uni.navigateTo({
						url:'../../pagesA/workbench/clinicalReception/doctorAdvice?item=' + JSON.stringify(that.orderInfo)
					})
				}
			},
			//发送视频
			choosevideo() {
				uni.chooseVideo({
					sourceType:['album', 'camera'],
					compressed: true,
					maxDuration:60,
					success: res => {
						that.showFunBtn = false;
						console.log('showFunBtn',res);
							that.$util.Upload(res.tempFilePath,function(data){
								console.log('JSON.parse(data.data)',JSON.parse(data.data));
								// console.log(data);
								data = JSON.parse(data.data)
								let temp = {
									"VideoUrl":data.data.video.URL,
									"VideoSize":data.data.video.Size,
									"VideoSecond":data.data.video.video_info.play_time,
									"VideoSecondText":data.data.video.video_info.duration,
									"VideoFormat":"mp4",
									"ThumbUrl":data.data.thump.URL,
									"ThumbSize":data.data.thump.Size,
									"ThumbWidth":data.data.thump.Width,
									"ThumbHeight":data.data.thump.Height,
									"ThumbFormat":data.data.thump.type
								}
								if(data.code == 1){
									let postData = {
										to_uid:that.orderInfo.uid,
										type:8,
										relation:that.orderInfo.order_id,
										content:JSON.stringify(temp)
									}
									that.$postAjax1('Doc_SendChat_doc_send_user',postData,function(data){
									})
								}else{
									uni.showToast({
										title: data.msg,
										icon: 'none',
										duration: 2500
									});
								}
							})
					}
				})
			},
			//格式化日期,// "yyyy-MM-dd hh:mm:sss"
			formatDate(n, t) {
				// console.log(n,t);
				n = new Date(n * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				var i, r, u;
				if (!n)
					return "";
				i = n;
				typeof n == "string" && (i = n.indexOf("/Date(") > -1 ? new Date(parseInt(n.replace("/Date(", "").replace(")/", ""),
					10)) : new Date(Date.parse(n.replace(/-/g, "/").replace("T", " ").split(".")[0])));
				r = {
					"M+": i.getMonth() + 1,
					"d+": i.getDate(),
					"h+": i.getHours(),
					"m+": i.getMinutes(),
					"s+": i.getSeconds(),
					"q+": Math.floor((i.getMonth() + 3) / 3),
					S: i.getMilliseconds()
				};
				/(y+)/.test(t) && (t = t.replace(RegExp.$1, (i.getFullYear() + "").substr(4 - RegExp.$1.length)));
				for (u in r) new RegExp("(" + u + ")").test(t) && (t = t.replace(RegExp.$1, RegExp.$1.length == 1 ? r[u] : ("00" +
					r[u]).substr(("" + r[u]).length)));
				return t
			},
			//发送图片
			chooseImage(sourceType) {
				uni.chooseImage({//uniapp提供的选取照片方法
					sourceType,
					sizeType: ['compressed'],
					success: res => {
						that.showFunBtn = false;
						console.log('res.tempFilePaths.length',res.tempFilePaths.length)
						for (let i = 0; i < res.tempFilePaths.length; i++) {
							that.$util.Upload(res.tempFilePaths[i],function(data){
								console.log('图片',JSON.parse(data.data));
								data = JSON.parse(data.data)
								if(data.code == 1){
									let postData = {
										to_uid:that.orderInfo.uid,
										type:6,
										relation:that.orderInfo.order_id,
										content:JSON.stringify(data.data)
									}
									that.$postAjax1('Doc_SendChat_doc_send_user',postData,function(data){
									})
								}else{
									uni.showToast({
										title: data.msg,
										icon: 'none',
										duration: 2500
									});
								}
							})
						}
					}
				})
			},
			//查看大图
			viewImg(imgList) {
				uni.previewImage({
					urls: imgList,
					// #ifndef MP-WEIXIN
					indicator: 'number'
					// #endif
				});
			},
			timeup() {
				console.log('时间到');
				// uni.showToast({
				// 	title: '时间到'
				// })
				let id = JSON.stringify(that.orderInfo.order_id)//深拷贝
				let ids = JSON.parse(id)//拷贝成功
				let postData = {
					orderId:that.orderInfo.order_id,
					status:that.orderInfo.consultation_type
				}
				that.$postAjax1('Doctor_getOrderInfo',postData,function(data){
					that.orderInfo = data.data.data
					that.orderInfo.order_id = ids
					that.messageList = []
					console.log(that.orderInfo,'用户详情');
					// 打开某个会话时，第一次拉取消息列表
					let promise = that.$tim.getMessageList({conversationID: 'C2Cuser_' + that.orderInfo.uid, count: 15});
					promise.then(function(imResponse) {
					  const messageList = imResponse.data.messageList; // 消息列表。
					  that.joinData(messageList,imResponse.data.isCompleted);
					  console.log(imResponse.data,'111111');
					  that.nextReqMessageID = imResponse.data.nextReqMessageID; // 用于续拉，分页续拉时需传入该字段。
					  // that.isCompleted = imResponse.data.isCompleted; // 表示是否已经拉完所有消息。
					});
				})
			},
			yidu(id){
				let postData = {
					order_sn:id,
				}
				that.$postAjax1('Doc_SendChat_send_read',postData,function(data){
					console.log(data,'已读上报')
				})
			},
			huanqi() {
				console.log('进来了00000');
				// #ifdef MP-WEIXIN
				uni.authorize({
					scope: 'scope.record',
					success(res) {
						console.log(res,'录音回调成功');
						uni.getRecorderManager()
						that.luyin_type = 1
					},
					fail(res) {
						console.log(res,'录音回调失败');
						uni.getSetting({
							// 获取权限信息
							success: response => {
								if (!response.authSetting['scope.record']) {
									uni.authorize({
										scope: 'scope.record',
										success() {
											// 同意摄像头权限后的事务
										},
										fail() {
											// 不同意摄像头权限后，引导用户开启
											if (uni.openSetting) {
												// 如果没有授权摄像头权限，引导用户开启
												that.openSettings();
											} 
											return;
										}
									})
								} else {
									// 同意摄像头权限后的事务
								}
							}
						})
					}
				})
				// #endif
				// #ifdef APP-PLUS
				console.log('录音回调成功');
				uni.getRecorderManager()
				that.luyin_type = 1
				// #endif
			},
			// 需求：引导用户手动开启摄像头的权限
			openSettings() {
			    wx.showModal({
			      title: '提示', //提示的标题,
			      content: '请打开麦克风权限', //提示的内容,
			      showCancel: true, //是否显示取消按钮,
			      cancelText: '取消', //取消按钮的文字，默认为取消，最多 4 个字符,
			      cancelColor: '#000000', //取消按钮的文字颜色,
			      confirmText: '确定', //确定按钮的文字，默认为取消，最多 4 个字符,
			      confirmColor: '#3CC51F', //确定按钮的文字颜色,
			      success: res => {
			        if (res.confirm) {
			          // openSetting 是需要事件驱动的，保证它的同步性。
			          wx.openSetting({
			            success(res) {
							console.log(res,'chenggong')
							if(res.authSetting['scope.record']){
								that.luyin_type = 1
							}
			            },
			            fail(res) {
							console.log(res,'失败回调')
			            }
			          })
			        } else if (res.cancel) {
			          console.log('用户点击取消')
			          wx.showToast({
			            title: '麦克风权限获取失败,语音功能无法使用',
			            icon: 'none',
			            duration: 3000,
			          })
			        }
			      }
			    });
			},
			checkSdkReady() {
				console.log('检测SDK 是否是 Ready 状态----', that.$store.state.tim.sdk_ready)
				if (!that.$store.state.tim.sdk_ready) {
					uni.showModal({
						title: '通信连接失败！',
						content: '可尝试重新进入该页面联系用户',
						showCancel: false,
						success: (res)=> {
							uni.switchTab({
								url: "/pages/workbench/workbench"
							})
						}
					});
				}
			}
		},
		onPageScroll(e) {
			if (e.scrollTop < 50) {
				if(that.IS == 0){
					that.IS = 1
					if(!that.isCompleted){
						setTimeout(function(){
							that.IS = 0
						},1000)
						// 下拉查看更多消息
						let promise = that.$tim.getMessageList({conversationID:'C2Cuser_' + that.orderInfo.uid,nextReqMessageID:that.nextReqMessageID,count: 15})
						promise.then(function(imResponse) {
						  const messageList = imResponse.data.messageList; // 消息列表。
						  that.joinData(messageList,imResponse.data.isCompleted);
						  that.nextReqMessageID = imResponse.data.nextReqMessageID
						  // that.isCompleted = imResponse.data.isCompleted; // 表示是否已经拉完所有消息。
						});
					}
				}
			}
		},
		onLoad(info) {
			console.log('onload')
			that = this
			that.$store.state.doc_type = 4
			that.huanqi()
			that.orderInfo = JSON.parse(info.item)
			console.log('that.orderInfo',that.orderInfo);
			// console.log('C2Cuser_' + that.orderInfo.userid);
			that.Audio = uni.createInnerAudioContext();
			console.log('that.$store.state.is_doc0',that.$store.state.is_doc)
			// var onMessageReceived
			if(that.$store.state.is_doc == 0){
				that.$store.state.is_doc = 1
				console.log('that.$store.state.is_doc1',that.$store.state.is_doc)
				let onMessageReceived = function(event) {
					
					console.log('测试一下有没有执行003========003')
					console.log('that.$store.state.doc_type',that.$store.state.doc_type,that.$store.state.is_doc)
					if(that.$store.state.doc_type == 4){
						console.log('医生端聊天页面开启监听' ,event);
						that.sendMsg(event.data)
						// 将某会话下所有未读消息已读上报
						that.yidu(that.orderInfo.order_id)
					}
					// 收到推送的单聊、群聊、群提示、群系统通知的新消息，可通过遍历 event.data 获取消息列表数据并渲染到页面
					// event.name - TIM.EVENT.MESSAGE_RECEIVED
					// event.data - 存储 Message 对象的数组 - [Message]
				};
				that.$tim.on(that.$TIM.EVENT.MESSAGE_RECEIVED, onMessageReceived);
			}
			that.checkSdkReady()

			//录音开始事件
			that.Recorder.onStart(e => {

				that.beginVoice();
			});
			//录音结束事件
			that.Recorder.onStop(res => {
				clearInterval(that.voiceInterval);
				that.handleRecorder(res);
			});
			
			//音频播放事件
			that.Audio.onPlay(e => {
				console.log(e,'音频播放');
				that.is_yuyin = 1
				// that.closeAnmition();
			});
			

			//音频停止事件
			that.Audio.onStop(e => {
				console.log(e,'音频停止');
				that.is_yuyin = 0
				that.closeAnmition();
			});

			//音频播放结束事件
			that.Audio.onEnded(e => {
				console.log(e,'音频结束');
				that.is_yuyin = 0
				that.closeAnmition();
			});
		},
		onShow() {
			that.$store.state.yaoList = []
			console.log('this.messageList',this.messageList)
		},
		onReady() {
			//自定义返回按钮 因为原生的返回按钮不可阻止默认事件
			// // #ifdef H5
			// const icon = document.getElementsByClassName('uni-page-head-btn')[0];
			// icon.style.display = 'none';
			// // #endif
			that.chufas()//获取常用语列表
			uni.setNavigationBarTitle({
				title: that.orderInfo.nickname
			});
			let id = JSON.stringify(that.orderInfo.order_id)//深拷贝
			let ids = JSON.parse(id)//拷贝成功
			let postData = {
				orderId:that.orderInfo.order_id,
				status:that.orderInfo.type
			}
			that.$postAjax1('Doctor_getOrderInfo',postData,function(data){
				that.orderInfo = data.data.data
				if(that.orderInfo.consultation_type == 3){
					that.funList[2].flag = true
				}
				that.orderInfo.order_id = ids
				console.log(that.orderInfo,'用户详情 onReady');
				// 打开某个会话时，第一次拉取消息列表
				let promise = that.$tim.getMessageList({conversationID: 'C2Cuser_' + that.orderInfo.uid, count: 15});
				promise.then(function(imResponse) {
				  const messageList = imResponse.data.messageList; // 消息列表。
				  that.joinData(messageList,imResponse.data.isCompleted);
				  console.log(imResponse.data,'医生端消息列表22');
				  that.nextReqMessageID = imResponse.data.nextReqMessageID; // 用于续拉，分页续拉时需传入该字段。
				  // that.isCompleted = imResponse.data.isCompleted; // 表示是否已经拉完所有消息。
				  // 将某会话下所有未读消息已读上报
				 that.yidu(that.orderInfo.order_id)
				});
			})
			
			uni.getSystemInfo({
				success: res => {
					that.imgHeight = res.windowHeight + 'px';
				}
			});

			uni.onKeyboardHeightChange(res => {
				if (res.height == 0) {
					// #ifdef MP-WEIXIN
					that.mpInputMargin = false;
					// #endif
				} else {
					that.showFunBtn = false;
				}
			});
		}
	};
</script>

<style lang="scss" scoped>
	@import './index.scss';
	.aa{background: #C0C0C0;}
	.bb{background: linear-gradient(270deg, #F78361 0%, #F54B64 100%);}
	.cc{height:540rpx;width:100%}
</style>
